package cn.csxw.openchina.ui.adapter;

import android.content.Intent;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zhy.autolayout.utils.AutoUtils;

import java.util.ArrayList;

import butterknife.BindView;
import cn.csxw.openchina.R;
import cn.csxw.openchina.base.BaseRecAdapter;
import cn.csxw.openchina.entity.bean.NewsBean;
import cn.csxw.openchina.ui.activity.NewsDetailActivity;
import cn.csxw.openchina.utils.Global;

/**
 * Created by hp on 2017/1/15.
 */

public class HotAdapter extends BaseRecAdapter<NewsBean> {
    private static ArrayList<String> infoList = new ArrayList<>();
    @Override
    protected void onItemClick(View v, int position) {
        NewsBean newsBean = mData.get(position);
        if(newsBean!=null){
            infoList.add(position+"");
            notifyDataSetChanged();
            Intent intent = new Intent(Global.mContext, NewsDetailActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.putExtra("hot", newsBean);
            Global.mContext.startActivity(intent);
        }
    }

    @Override
    protected BaseViewHolder getViewHolder(View itemView) {
        AutoUtils.autoSize(itemView);
        return new HotHolder(itemView);
    }

    @Override
    protected View getItemView(ViewGroup parent) {
        View itemView = Global.inflate(R.layout.layout_news_rv_item,parent);
        return itemView;
    }

    class HotHolder extends BaseViewHolder {
        @BindView(R.id.iv_content_type)
        ImageView mIvContentType;
        @BindView(R.id.tv_news_title)
        TextView mTvNewsTitle;
        @BindView(R.id.tv_news_content)
        TextView mTvNewsContent;
        @BindView(R.id.tv_author)
        TextView mTvAuthor;
        @BindView(R.id.iv_news_time)
        ImageView mIvNewsTime;
        @BindView(R.id.tv_news_time)
        TextView mTvNewsTime;
        @BindView(R.id.iv_news_message)
        ImageView mIvNewsMessage;
        @BindView(R.id.tv_message_count)
        TextView mTvMessageCount;
        @BindView(R.id.ll_news)
        LinearLayout mLlNews;

        public HotHolder(View itemView) {
            super(itemView);
            AutoUtils.autoSize(itemView);
        }

        @Override
        public void setData(NewsBean newsBean, int position) {
            if (newsBean != null) {
                if(infoList.contains(position+"")){
                    mTvNewsTitle.setTextColor(Color.parseColor("#ff808080"));
                }else {
                    mTvNewsTitle.setTextColor(Color.parseColor("#ff333333"));
                }
                mTvNewsTitle.setText(newsBean.title);
                mTvNewsContent.setText(newsBean.body);
                mTvAuthor.setText(newsBean.author);
                mTvNewsTime.setText(newsBean.pubDate);
                mTvMessageCount.setText(newsBean.commentCount+"");
                mIvContentType.setVisibility(View.GONE);
            }
        }
    }
}
